//
//  XGMainViewController.m
//  Instagram
//
//  Created by monkey on 2019/4/13.
//  Copyright © 2019 itcast. All rights reserved.
//

#import "XGMainViewController.h"
#import "XGBaseNavigationViewController.h"
#import "XGHomeViewController.h"
#import "XGMineViewController.h"

@implementation XGMainViewController

#pragma mark - 构造方法

- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
        [self addAllChildViewControllers];
    }
    
    return self;
}

#pragma mark - 控制器生命周期方法

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    // 设置渲染颜色
    UITabBar *tabBar = [UITabBar appearanceWhenContainedInInstancesOfClasses:@[[self class]]];
    tabBar.tintColor = [UIColor orangeColor];
}

#pragma mark - 其他方法

/// 设置支持方向
- (UIInterfaceOrientationMask)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskPortrait;
}

/// 添加所有子控制器
- (void)addAllChildViewControllers
{
    [self addChildController:[[XGHomeViewController alloc] init] title:@"首页" normalImageName:@"tabbar_home" selectedImageName:@"tabbar_home_highlighted"];
    [self addChildController:[[XGMineViewController alloc] init] title:@"我的" normalImageName:@"tabbar_profile" selectedImageName:@"tabbar_profile_highlighted"];
}

/**
 添加子控件

 @param viewController 控制器
 @param title 标题
 @param normalImageName 普通状态图片
 @param selectedImageName 选中状态图片
 */
- (void)addChildController:(UIViewController *)viewController title:(NSString *)title normalImageName:(NSString *)normalImageName selectedImageName:(NSString *)selectedImageName
{
    viewController.title = title;
    viewController.tabBarItem.image = [UIImage imageNamed:normalImageName];
    viewController.tabBarItem.selectedImage = [UIImage originalImageWithImageName:selectedImageName];
    UINavigationController *nav = [[XGBaseNavigationViewController alloc] initWithRootViewController:viewController];
    [self addChildViewController:nav];

}

@end
